package com.example.demo.config;

import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.UUID;

@Configuration
@Data
@Slf4j
@ConditionalOnProperty(name = "xxl.job.enabled", havingValue = "true", matchIfMissing = true) // havingValue true时启动  matchIfMiss 默认true
public class XxlJobConfig {

    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobExecutor xxlJobExecutor() {
        //  XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
        //  xxlJobExecutor.setAdminAddresses("http://127.0.0.1:8080/xxl-job-admin");
        //  xxlJobExecutor.setAppName("xxl-job-executor-sample");
        //  xxlJobExecutor.setAppname("xxl-job-executor-chao");
        //  xxlJobExecutor.setIp("");
        //  xxlJobExecutor.setPort(9999);
        //  xxlJobExecutor.setAccessToken("");
        //  xxlJobExecutor.setLogPath("/data/applogs/xxl-job/jobhandler");
        //  xxlJobExecutor.setLogRetentionDays(30);

        log.info(">>>>>>>>>>> xxl-job - chao config init.");

        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses("http://172.16.20.224:8056/xxl-job-admin");
        xxlJobSpringExecutor.setAppname("xxl-job-executor-chao");
        xxlJobSpringExecutor.setAddress("");
        xxlJobSpringExecutor.setIp("");
        xxlJobSpringExecutor.setPort(0);
        xxlJobSpringExecutor.setAccessToken("123456789");
//        xxlJobSpringExecutor.setAccessToken(UUID.randomUUID().toString().replace("-", ""));
        xxlJobSpringExecutor.setLogPath("/data/applogs/xxl-job/jobhandler");
        xxlJobSpringExecutor.setLogRetentionDays(30);

        return xxlJobSpringExecutor;
    }

}
